package com.dome.common.pojo;

import com.dome.common.enumeration.DomeErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Collection;
import java.util.List;

@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class PageResponse<DATA> extends DomeResponse<Collection<DATA>> {

    private int pageNo = 0;
    private int pageSize = 10;
    private long totalPageCount = 1;
    private long totalItemCount = 0;

    public static <T> PageResponse<T> ofPage(Pagination<T> page) {
        PageResponse<T> pr = new PageResponse<>();
        pr.setErrorCode(DomeErrorCode.SUCCESS.getCode());
        pr.setErrorMsg(DomeErrorCode.SUCCESS.getDesc());
        pr.setTotalItemCount(page.getTotalItemCount());
        pr.setTotalPageCount(page.getTotalPageCount());
        pr.setPageNo(page.getPageNo());
        pr.setPageSize(page.getPageSize());
        pr.setData(page.getData());
        return pr;
    }

}
